<template>
    <div id="wrap">
        <Header></Header>
        <HeaderNav :headerlist="headerlist"></HeaderNav>
        <div id="navigation">
            <div class="container">
                <a href="">首页</a>
                <!-- <a href="">{{categoryList.name}}</a> -->
                <a href="">{{title}}</a>
            </div>
        </div>
        <div class="main">
            <div class="container">
                <!-- <NavLeft :MainList="mainList" /> -->
                <Swiper />

            </div>
        </div>
        <div class="category">
            <div class="container">
                <div class="category_list">
                    <h3>全部分类</h3>
                    <ul>
                        <li v-for="item in categoryList.children">
                            <a href="javascript:;">
                                <img :src="item.picture" alt="">
                                <p>{{ item.name }}</p>
                            </a>
                        </li>
                    </ul>
                </div>
                <div class="category_goods" v-for="item in categoryList.children">
                    <div class="container">
                        <div class="head">
                            <h3>- {{ item.name }} -</h3>
                            <p>温暖柔软，品质之选</p>
                            <span class="more">查看全部&gt;</span>
                        </div>
                        <ul class="content">
                            <li v-for="i in item.goods">
                                <img :src="i.picture" alt="">
                                <p>{{ i.name }}</p>
                                <p>{{ i.desc }}</p>
                                <p>￥{{ i.price }}</p>
                            </li>
                        </ul>
                    </div>
                </div>
            </div>
        </div>

    </div>
</template>

<script>
import Header from '@/page/Main/Header'
import HeaderNav from '@/page/Main/HeaderNav'
import Swiper from '@/page/Main/swiper'
import NavLeft from '@/page/Main/NavLeft'
export default {
    components: {
        Header,
        HeaderNav,
        NavLeft,
        Swiper,
    },
    data() {
        return {
            categoryList: [],
            GoodsList: [],
            headerlist: [],
            mainList: [],
            title:''
        }
    },
    methods: {
        getCategoryId() {
            var id = this.$route.params.id
            this.axios.get(`https://apipc-xiaotuxian-front.itheima.net/category?id=${id}`).then(res => {
                if (res.data.msg == '操作成功') {
                    this.categoryList = res.data.result
                    // console.log(res.data.result);
                    this.title = this.$route.meta.title

                }
            })
        },
        
    },
    watch: {
        '$route': 'getCategoryId'
    },
    mounted() {
        this.getCategoryId()

        this.axios.get('https://apipc-xiaotuxian-front.itheima.net/home/category/head').then(res => {
            if (res.data.msg == '操作成功') {
                this.headerlist = res.data.result  // 头部导航
                this.mainList = res.data.result  // 选项卡
            }
        })
        this.axios.get('https://apipc-xiaotuxian-front.itheima.net/home/goods').then((res) => {
            if (res.data.msg == '操作成功') {
                this.GoodsList = res.data.result
            }
        })
    },
    // beforeRouteUpdate(to,from,next){
    //     console.log(to,from);
    //     next()
    // }
}
</script>
<style lang="scss" scoped>
#navigation {
    display: flex;
    padding: 25px 10px;

    a {
        color: #666;
        transition: all .4s;
    }

    i {
        font-size: 12px;
        margin-left: 5px;
        margin-right: 5px;
        line-height: 22px;
    }
}

.category_list {
    margin-top: 20px;
    background-color: #fff;

    h3 {
        font-size: 28px;
        color: #666;
        font-weight: 400;
        text-align: center;
        line-height: 100px;
    }

    ul {
        display: flex;
        padding: 0 32px;
        flex-wrap: wrap;
        min-height: 160px;

        li {
            width: 168px;
            height: 160px;

            a {
                text-align: center;
                display: block;
                font-size: 16px;

                img {
                    width: 100px;
                    height: 100px;
                    vertical-align: middle;
                }

                p {
                    line-height: 40px;
                }
            }
        }
    }
}

.category_goods {
    background-color: #fff;
    margin-top: 20px;
    position: relative;

    .head {
        h3 {
            font-size: 28px;
            color: #666;
            font-weight: 400;
            text-align: center;
            line-height: 100px;
        }

        p {
            text-align: center;
            color: #999;
            font-size: 20px;
            position: relative;
            top: -20px;
        }

        span {
            position: absolute;
            top: 20px;
            right: 20px;
            font-size: 16px;
            vertical-align: middle;
            margin-right: 4px;
            color: #999;
        }
    }
}

.content {
    display: flex;
    justify-content: flex-start;
    flex-wrap: wrap;
    padding: 0 65px 30px;
    // .hover{
    //     transform: translate3d(0,-3px,0);
    // box-shadow: 0 3px 8px rgb(0 0 0 / 20%);
    // }

    li {
        width: 220px;
        padding: 20px 30px;
        text-align: center;
        transition: all .5s;

        &:hover {
            transform: translate3d(0, -3px, 0);
            box-shadow: 0 3px 8px rgb(0 0 0 / 20%);
        }

        img {
            width: 160px;
            height: 160px;
            vertical-align: middle;
        }

        p {
            padding-top: 10px;
            text-overflow: ellipsis;
            overflow: hidden;
            white-space: nowrap;

            &:nth-of-type(1) {
                font-size: 16px;
            }

            &:nth-of-type(2) {
                color: #999;
                height: 29px;
            }

            &:nth-of-type(3) {
                color: #cf4444;
                font-size: 20px;
            }
        }
    }
}
</style>